package cn.lds.j368.dsbank.service.impl;

import cn.lds.j368.dsbank.domain.SysLog;
import cn.lds.j368.dsbank.domain.SysLogParams;
import cn.lds.j368.dsbank.mapper.SysLogMapper;
import cn.lds.j368.dsbank.mapper.SysLogParamsMapper;
import cn.lds.j368.dsbank.service.SysLogService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;
import java.util.Map;

@Service
public class SysLogServiceImpl implements SysLogService {

    @Autowired
    private SysLogMapper sysLogMapper;

    @Autowired
    private SysLogParamsMapper sysLogParamsMapper;

    @Override
    public List<SysLog> selectSysLogAll(String username) {

        QueryWrapper<SysLog> sysLogQueryWrapper = new QueryWrapper<>(new SysLog()).eq(!StringUtils.isEmpty(username),"emp_username",username);


        return sysLogMapper.selectList(sysLogQueryWrapper);
    }

    @Override
    public int addSysLog(SysLog sysLog, List<SysLogParams> sysLogParams) {

        int insert = sysLogMapper.insert(sysLog);

        sysLogParams.forEach(p->{
            p.setSysLogId(sysLog.getSysLogId());
            sysLogParamsMapper.insert(p);
        });



        return insert;
    }
}
